from unittest import TestCase
from ddt import ddt, data, unpack
from selenium import webdriver
from LoginOperation import LoginOperation
from LoginData import LoginData


@ddt
class TestLogin(TestCase):

    @data(*LoginData.login_data)
    @unpack
    def testLogin1(self, casename, name, pwd, expect):
        #  开始测试
        driver = webdriver.Chrome()
        # 打开浏览器页面并最大化
        driver.get("file:///D:/WeChat%20Files/wxid_ho1z2hz3uaqm22/FileStorage/File/2023-07/Login%E6%BC%94%E7%A4%BA%E9%A1%B5%E9%9D%A2/login.html")
        driver.maximize_window()
        # 执行登录
        login = LoginOperation()
        login.login(driver, name, str(int(pwd)))
        # 获取登陆成功结果
        result = login.getSuccessResult(driver)

        if result != expect:
            driver.save_screenshot(casename + ".jpg")
        else:
            print("通过")

        driver.quit()

        self.assertEquals(expect, result)
